package cn.schoolwow.util.test.module.query.reflection.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.reflection.FieldFilter;
import cn.schoolwow.util.domain.query.reflection.QueryReflection;
import cn.schoolwow.util.domain.query.reflection.QueryReflectionResponse;
import cn.schoolwow.util.test.module.common.domain.User;
import org.junit.Assert;

import java.lang.reflect.Field;
import java.util.List;

public class QueryReflectionProcessFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QueryReflectionResponse queryReflectionResponse = QueryReflection.newQuery(User.class)
                .addQuery("username")
                .addQuery("password")
                .addQuery(new FieldFilter() {
                    @Override
                    public boolean filterField(Field field) {
                        return true;
                    }
                })
                .execute();
        List<Field> fieldList = queryReflectionResponse.getFieldList();
        Assert.assertEquals(2, fieldList.size());

        Field field = QueryReflection.newQuery(User.class)
                .execute()
                .getField("username");
        User user = new User();
        field.set(user, "username");
    }

    @Override
    public String name() {
        return "查询用户反射用例";
    }
}
